#include "hzpch.h"
#include "SceneCamera.h"

#include <glm/gtc/matrix_transform.hpp>

namespace Hazal
{
	CSceneCamera::CSceneCamera()
	{
		RecaculateProjection();
	}

	CSceneCamera::~CSceneCamera()
	{

	}

	void CSceneCamera::SetOrthographic(float fSize, float fNearClip, float fFarCilp)
	{
		m_eProjectionType = ProjectionType::Orthographic;

		m_fOrthographicSize = fSize;
		m_fOrthographicNear = fNearClip;
		m_fOrthographicFar = fFarCilp;

		RecaculateProjection();
	}

	void CSceneCamera::SetPerspective(float fVerticalFOV, float fNearClip, float fFarClip)
	{
		m_eProjectionType = ProjectionType::Orthographic;

		m_fPerspectiveFOV = fVerticalFOV;
		m_fPerspectiveNear = fNearClip;
		m_fPerspectiveFar = fFarClip;

		RecaculateProjection();
	}

	void CSceneCamera::SetViewportSize(uint32_t unWidth, uint32_t unHeight)
	{
		m_fAspectRadio = (float)unWidth / (float)unHeight;
	
		RecaculateProjection();
	}

	void CSceneCamera::RecaculateProjection()
	{
		if (ProjectionType::Orthographic == m_eProjectionType)
		{
			float fOrthoLeft = -0.5f * m_fAspectRadio * m_fOrthographicSize;
			float fOrthoRight = 0.5f * m_fAspectRadio * m_fOrthographicSize;
			float fOrthoBottom = -0.5f * m_fOrthographicSize;
			float fOrthoTop = 0.5f * m_fOrthographicSize;

			m_matProjection = glm::ortho(fOrthoLeft, fOrthoRight, fOrthoBottom, fOrthoTop, m_fOrthographicNear, m_fOrthographicFar);
		}
		else if (ProjectionType::Perspective == m_eProjectionType)
		{
			m_matProjection = glm::perspective(m_fPerspectiveFOV, m_fAspectRadio, m_fPerspectiveNear, m_fPerspectiveFar);
		}
		else
		{
			// TODO
		}

	}
}